package com.huike.web.controller.review;


import com.huike.common.constant.HttpStatus;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.model.LoginUser;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import com.huike.framework.web.service.TokenService;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;
    @Autowired
     private  TokenService  tokenService;
    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult saveData(@PathVariable String name, @PathVariable Integer age, @PathVariable String sex, HttpServletRequest request){
        Long userId = SecurityUtils.getUserId();
        System.out.println("id-----------"+userId);
        reviewService.save(name,age,sex);
        return new AjaxResult(HttpStatus.SUCCESS,"成功插入一条数据");
    }
    @PostMapping("/saveData")
    public AjaxResult saveOne(@RequestBody Review review){
        reviewService.saveOne(review);
        return new AjaxResult(HttpStatus.SUCCESS,"成功插入一条数据");
    }
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Review review){
        reviewService.update(review);
        return new AjaxResult(HttpStatus.SUCCESS,"修改成功");
    }

    @DeleteMapping("/remove/{id}")
    public AjaxResult delete(@PathVariable Integer id){
        reviewService.delete(id);
        return new AjaxResult(HttpStatus.SUCCESS,"成功删除1条数据");
    }
    @GetMapping("/getById")
    public AjaxResult getById( Integer id){
      Review review =  reviewService.getById(id);
        return new AjaxResult(HttpStatus.SUCCESS,"操作成功",review);
    }
    @GetMapping("/getDataByPage")
  public TableDataInfo page(Integer pageNum,Integer pageSize){
        TableDataInfo tableDataInfo = reviewService.page(pageNum,pageSize);
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("查询成功");
        return tableDataInfo;
    }
    /**=========================================================新增数据============================================*/

    /**=========================================================删除数据=============================================*/

    /**=========================================================修改数据=============================================*/

    /**=========================================================查询数据=============================================*/

}